//
//  SHKViewController.m
//  YsGetPictureClip
//
//  Created by John01 on 04/08/2020.
//  Copyright (c) 2020 John01. All rights reserved.
//

#import "SHKViewController.h"
#import <YsGetPictureClip/YsGetPictureClip.h>
#import <Masonry/Masonry.h>
#import <ReactiveObjC/ReactiveObjC.h>

@interface SHKViewController ()
@property (nonatomic, strong) YsGetPictureClipManager *getPictureClipManager;
@property (nonatomic, strong) UIImageView *imageView;

@end

@implementation SHKViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    UIImageView *imageView = [[UIImageView alloc] init];
    self.imageView = imageView;
    [self.view addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(100);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    
    
    UIButton *btn  = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = UIColor.purpleColor;
    [btn setTitle:@"相册" forState:0];
    [self.view addSubview:btn];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(100);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    
    UIButton *btn1  = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.backgroundColor = UIColor.greenColor;

     [btn1 setTitle:@"拍照" forState:0];
     [self.view addSubview:btn1];
     
     [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
         make.centerX.mas_equalTo(0);
         make.top.mas_equalTo(btn.mas_bottom).offset(10);
         make.size.mas_equalTo(CGSizeMake(100, 100));
     }];
    
   @weakify(self);
    [[btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
            [YsGetPictureClipManager.shareManger pushImagePickerWithVC:self type:YsGetPictureClipTypeAlbum addHandlersForcompleted:^(UIImage * _Nullable image, id  _Nullable asset) {
                @strongify(self);
                if (image) {
                    self.imageView.image = image;
                }
            }];
    }];
    
    [[btn1 rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
              [YsGetPictureClipManager.shareManger pushImagePickerWithVC:self type:YsGetPictureClipTypeCamera addHandlersForcompleted:^(UIImage * _Nullable image, id  _Nullable asset) {
                  if (image) {
                      @strongify(self);
                      self.imageView.image = image;
                  }
              }];
      }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{

}


- (void)dealloc
{
    NSLog(@"%s",__func__);
}
@end
